package com.liangtian.mdm.base.constants;

/**
 * 响应值,使用5位响应码，Y代表系统异常，A代表项目本身，C代表第三方服务
 * @author Qi
 */
public enum ResultCode {
    SUCCESS("Y0000", "成功"),
    FAIL("Y9999", "服务器内部错误"),
    FAIL_REQ_PARAM_ERROR("Y9001", "参数有误"),
    FAIL_JSON_PARSING_EXCEPTION("Y9002", "json解析异常"),
    //表示用户没有权限（令牌、用户名、密码错误）
    FAIL_NO_PERMISSION("Y9003", "无权执行该操作"),
    FAIL_LOGIN_NO_PERMISSION_ON_CLIENT("Y9004", "无权登录该程序"),
    FAIL_EXECUTE_SQL("Y9005", "SQL执行失败"),


    //通用模块 A01
    REGISTER_FAIL("A0100", "用户注册错误"),
    ACCESS_TOKEN_EXPIRED("A0101", "Token无效，请重新登录"),
    USER_NOT_EXIST("A0103", "用户不存在"),
    USER_HAS_EXIST("A0104", "用户已存在"),
    RESET_PASSWORD_FAIL("A0105", "重置密码失败"),
    USER_LOGIN_FAIL("A0106", "登录失败"),
    LOGIN_FAIL_COUNT_OVERFLOW("A0107", "连续输错5次密码，需要使用图片验证码"),
    USER_LOGIN_NOT_ALLOW("A0108", "用户已被禁止登陆"),
    USER_UPDATE_PASSWORD_ERROR("A0109", "原始密码错误"),

    QUERY_FAILED("A0110","查询失败"),
    INSERT_FAILED("A0111","新增失败"),
    UPDATE_FAILED("A0112","更新失败"),
    DELETE_FAILED("A0113","删除失败"),

    IMPORTED_FILE_IS_EMPTY("A0120","导入的文件为空"),
    IMPORTED_DATA_HAS_EXIST("A0121","导入的数据已存在"),
    EXPORTED_DATA_IS_EMPTY("A0122","没有要导出的数据"),

    //物料模块
    WL_JLDW_HAS_EXIST("A0200","物料计量单位已存在"),
    WL_JLDW_NOT_EXIST("A0201","物料计量单位不存在"),
    WL_FH_HAS_EXIST("A0301","物料符号已存在"),
    WL_FH_NOT_EXIST("A0301","物料符号不存在"),

    //第三方调用相关错误码
    // C01 中间件服务出错
    CACHE_SET_ERROR("C0101", "存储数据到缓存中失败"),
    FTP_ERROR("C0201", "FTP错误"),
    ;

    private final String code;
    private final String msg;

    ResultCode(final String code, final String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ResultCode fromCode(String code) {
        ResultCode[] ecs = ResultCode.values();
        for (ResultCode ec : ecs) {
            if (ec.getCode().equals(code)) {
                return ec;
            }
        }
        return null;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }
}
